import 'package:flutter/material.dart';
import 'package:flutter_scan_tool/models/app_theme.dart';
import 'package:flutter_scan_tool/models/tool.dart';
import 'package:flutter_scan_tool/page/tool_info_log_page.dart';
import 'package:flutter_scan_tool/page/tool_list_view.dart';

class ToolInfoListView extends StatelessWidget {
  const ToolInfoListView({
    Key? key,
    required this.toolList,
    required this.animationController,
  }) : super(key: key);

  final List<ToolData> toolList;
  final AnimationController? animationController;

  @override
  Widget build(BuildContext context) {
    return Container(
      color: AppTheme.appTheme.containerBackgroundColor(),
      child: ListView.builder(
          itemCount: toolList.length,
          padding: const EdgeInsets.only(top: 8.0),
          scrollDirection: Axis.vertical,
          itemBuilder: (BuildContext context, int index) {
            final int count = toolList.length > 10 ? 10 : toolList.length;
            final Animation<double> animation =
            Tween<double>(begin: 0.0, end: 1.0).animate(CurvedAnimation(
                parent: animationController!,
                curve: Interval((1 / count) * index, 1,
                    curve: Curves.fastOutSlowIn)));
            animationController?.forward();
            return ToolListView(
              callback: () {
                Navigator.push(context, MaterialPageRoute(builder: (context) {
                  return ToolInfoLogPage(
                    toolData: toolList[index],
                  );
                }));
              },
              toolListData: toolList[index],
              animation: animation,
              animationController: animationController!,
            );
          }),
    );
  }
}